package client.handler;

import client.Client;
import unit.response.GetContactListRequestResponse;
import unit.response.Response;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: victorn
 * Date: 8/24/11
 * Time: 11:22 PM
 * To change this template use File | Settings | File Templates.
 */
public class GetContactListResponseHandler extends AbstractResponseHandler {
    GetContactListResponseHandler(Client client) {
        super(client);
    }

    @Override
    public void handleRequest(Response response) {

        int[] userIds = ((GetContactListRequestResponse) response).getUserIds();
        String[] projective = ((GetContactListRequestResponse) response).getProjective();
        String[][] values = ((GetContactListRequestResponse) response).getValues();

        Map<Integer, Map<String, String>> contacts = new HashMap<Integer, Map<String, String>>();

        Map<String, String> userInfo;

        for (int i = 0; i < userIds.length; i++) {

            userInfo = new HashMap<String, String>();

            for (int j = 0; j < projective.length; j++) {
                userInfo.put(projective[j], values[i][j]);
            }

            contacts.put(userIds[i], userInfo);
        }

        client.clientInterface.setContactList(contacts);

    }
}
